

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>validate验证框架演示</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta http-equiv="Page-Enter" content="revealTrans(duration=1, transition=2)"/><meta http-equiv="Page-Exit" content="revealTrans(duration=1, transition=2)"/>
		<link type="text/css" rel="stylesheet" href="../js/validate/css/validate.css" /> 
		<script src="../js/validate/talent-validate-all.js" language="javascript"></script><script src="./demo.js" language="javascript"></script>  <!-- 第一步 -->
		</head><body>
			<form name="form1">
				用户名和密码都是talent时通过，否则不通过
				<br/>
				<br/>
				用户名<input type="text" value="talent" id='username' name="username" onfocus='userNamettCV.rm("username");'/>
				<br/>
				密码<input type="password" value="2" id='password' name="password" onfocus='passwordttCV.rm("password");'/>
				<br/>
				<input type="button" class='button' value="验证" onclick="myValidate()"/>
			
			</form>
		</body>
	
		<!-- 第二步 -->
		<script id="talent_script">
			tt.vf.req.add('username', "password");

			var userNamettCV = new tt.CV();
			var passwordttCV = new tt.CV();

			function myValidate() {
				var username = document.getElementById('username');
				var password = document.getElementById('password');
				
				//先取消两个字段的验证
				passwordttCV.rm("password");
				userNamettCV.rm("username");

				//根据username和password，利用ajax从后台查询是否存在这样的用户
				if (username.value != 'talent') {
					userNamettCV.add(new tt.Field('用户名', "username")).set('v', '==', 'talent', false);
					return tt.validate();
				}
				
				//判断密码是否正确
				if (password.value != 'talent') {
					passwordttCV.add(new tt.Field('密码', "password")).set('v', '==', 'talent', false);
					return tt.validate();
				}

				return tt.validate();
			}
		</script>
</html>
